package com.ruoyi.web.controller.nongjt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.nongjt.domain.Work;
import com.ruoyi.nongjt.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作Controller
 */
@RestController
@RequestMapping("/nongjt/njt/work")
public class work_controller extends BaseController {

    @Autowired
    private WorkService workService;

    /**
     * 查询工作列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(Work work) {
        startPage();
        List<Work> list = workService.selectWorkList(work);
        return getDataTable(list);
    }

    /**
     * 获取工作详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workService.selectWorkById(id));
    }

    /**
     * 新增工作
     */
    @PreAuthorize("@ss.hasPermi('nongjt:work:add')")
    @Log(title = "工作管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Work work) {
        return toAjax(workService.insertWork(work));
    }

    /**
     * 修改工作
     */
    @PreAuthorize("@ss.hasPermi('nongjt:work:edit')")
    @Log(title = "工作管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Work work) {
        return toAjax(workService.updateWork(work));
    }

    /**
     * 删除工作
     */
    @PreAuthorize("@ss.hasPermi('nongjt:work:remove')")
    @Log(title = "工作管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        int result = 0;
        for (Long id : ids) {
            result += workService.deleteWorkById(id);
        }
        return toAjax(result);
    }
}
